package com.tools.gensql.service;

import cn.hutool.db.DbUtil;
import lombok.extern.slf4j.Slf4j;
import org.noear.solon.annotation.Component;
import org.noear.solon.annotation.Init;

@Component
@Slf4j
public class InitDbService {

    @Init
    public void init() {
        try {
            var sql = """
                    create table if not exists DB_CONNECTION
                    (
                        ID       BIGINT auto_increment
                            primary key,
                        NAME     CHARACTER VARYING(255) not null,
                        TYPE     CHARACTER VARYING(50)  not null,
                        HOST     CHARACTER VARYING(255) not null,
                        PORT     INTEGER,
                        DATABASE CHARACTER VARYING(255),
                        USERNAME CHARACTER VARYING(255),
                        PASSWORD CHARACTER VARYING(255),
                        CATALOG  CHARACTER VARYING(255)
                    );
                    create table if not exists APP_CONFIG
                    (
                        ID       BIGINT auto_increment primary key,
                        CONFIG_KEY     varchar(1024) null,
                        CONFIG_VALUE     varchar(1024) null,
                        CONFIG_COMMENT     varchar(1024) null
                    );
                    """;
            DbUtil.use().execute(sql);
        } catch (Exception ignore) {
        }
    }
}
